<?php

namespace App\Containers\AppSection\Data\UI\API\Transformers;

use App\Containers\AppSection\Data\Models\Company;
use App\Containers\AppSection\File\UI\API\Transformers\FileTransformer;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Collection;

class CompanyTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'charters'
    ];

    /**
     * @var  array
     */
    protected array $availableIncludes = [

    ];

    public function transform(Company $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'name' => $t->name,
            'ogrn' => $t->ogrn,
            'inn' => $t->inn,
            'charters' => $t->charters,
            'legal_address' => $t->legal_address,
            'actual_address' => $t->actual_address,
            'address_matches' => $t->address_matches,
            'created_at' => $this->dateFormatter($t->created_at),
            'updated_at' => $this->dateFormatter($t->updated_at),
            'readable_created_at' => $t->created_at->diffForHumans(),
            'readable_updated_at' => $t->updated_at->diffForHumans()
        ];
    }

    public function includeCharters(Company $t): Collection
    {
        return $this->collection($t->charters()->get(), new FileTransformer);
    }
}
